<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="8">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
              <select-project-input
                :disabled="projectFlag || showFlowSubmitButton"
                v-model="model.projectId"
                placeholder="请选择关联项目"
                :teamId="layout.model.teamId"
                :companyId="layout.model.companyId"
                :queryParamType="'1'"
                @input="selectProject" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectCode">
              <a-input disabled v-model="model.projectCode" placeholder="请输入项目编号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attributionYear">
              <j-dict-select-tag disabled type="list" v-model="model.attributionYear" dictCode="yjgsnd" placeholder="请选择归属年度"/>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="项目阶段" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectType">
              <j-dict-select-tag :disabled="projectFlag" placeholder="请选择项目阶段" v-model="model.projectType" dictCode="project_status"/>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="8">
            <a-form-model-item
              label="任务分类"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="taskId"
            >
              <select-project-task-input
                :disabled="projectFlag || showFlowSubmitButton"
                v-model="model.taskId"
                placeholder="请选择任务分类"
                :projectId="model.projectId"
                :isRefresh="true"
                @back="taskBack"
                :is-flow-cancel="'running'"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="isRelProject!='1'">
            <a-form-model-item label="任务说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskDescription">
              <a-input :disabled="datailDisabled || showFlowSubmitButton" v-model="model.taskDescription" placeholder="请输入任务说明" ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="费用所属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamYear">
              <j-dict-select-tag :disabled="projectFlag" placeholder="请选择费用所属年度" v-model="model.teamYear" dictCode="tdnd_type"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="费用所属团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamId">
              <select-team-input placeholder="请选择费用所属团队" :disabled="projectFlag" v-model="model.teamId" :tdlx="3" />
            </a-form-model-item>
          </a-col> -->
          
          <a-col :span="8">
            <a-form-model-item label="出发时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="setOutTime">
              <a-date-picker :disabled="formDisabled || showFlowSubmitButton" :show-time="{ format: 'HH' }" placeholder="请选择出发时间" format="YYYY-MM-DD HH" v-model="model.setOutTime" @change="calculateDays()" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="回程时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="backTime">
              <a-date-picker :disabled="formDisabled || showFlowSubmitButton" :show-time="{ format: 'HH' }" placeholder="请选择回程时间" format="YYYY-MM-DD HH" :disabled-date="disabledDate" v-model="model.backTime" @change="calculateDays()" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="出差天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="days">
              <a-input :disabled="datailDisabled || showFlowSubmitButton" v-model="model.days" placeholder="请输入出差天数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="detailFlag">
            <a-form-model-item label="报销内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feeType">
              <j-dict-select-tag :disabled="formDisabled" placeholder="请选择报销内容" v-model="model.feeType" dictCode="reimbursement_content" @input="feeTypeInput"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="detailFlag">
            <a-form-model-item label="交通方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="transportMode">
              <j-dict-select-tag :disabled="formDisabled || showFlowSubmitButton" placeholder="请输入交通方式" v-model="model.transportMode" dictCode="transportation"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="!detailFlag">
            <a-form-model-item label="报销内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="selfDriving">
              <j-dict-select-tag :disabled="formDisabled" placeholder="请选择报销内容" v-model="model.selfDriving" dictCode="expense_account"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="!detailFlag">
            <a-form-model-item label="交通方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="selfDrivingMode">
              <j-dict-select-tag :disabled="formDisabled || showFlowSubmitButton" placeholder="请输入交通方式" v-model="model.selfDrivingMode" dictCode="traffic"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="出发地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departurePlace">
              <!-- <j-area-linkage :disabled="formDisabled" type="cascader" v-model="model.departurePlace" placeholder="请选择出发地点"/> -->
              <AddressChoice type="cascader" :disabled="formDisabled || showFlowSubmitButton" v-model="model.departurePlace" placeholder="请选择出发地点"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="到达地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="targetPlace">
              <!-- <j-area-linkage :disabled="formDisabled" type="cascader" v-model="model.targetPlace" placeholder="请选择出到达地点"/> -->
              <AddressChoice type="cascader" :disabled="formDisabled || showFlowSubmitButton" v-model="model.targetPlace" placeholder="请选择出到达地点"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="detailFlag">
            <a-form-model-item label="发票类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isSpecial">
              <j-dict-select-tag
                :disabled="formDisabled"
                v-model="model.isSpecial"
                dictCode="invoice_type"
                placeholder="请选择发票类型"
                @input="specialInput"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="!detailFlag">
            <a-form-model-item label="出发里程数(km)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startMileage">
              <a-input-number
                :disabled="formDisabled || showFlowSubmitButton"
                :max="99999999"
                :min="0"
                v-model="model.startMileage"
                @change="calculateMileage()"
                placeholder="请输入出发里程数(交通方式为自驾时有用)"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="!detailFlag">
            <a-form-model-item label="返程里程数(km)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endMileage">
              <a-input-number
                :disabled="formDisabled || showFlowSubmitButton"
                :max="99999999"
                :min="0"
                v-model="model.endMileage"
                @change="calculateMileage()"
                placeholder="请输入返程里程数(交通方式为自驾时有用)"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="!detailFlag">
            <a-form-model-item label="里程数(km)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mileage">
              <a-input-number
                :disabled="datailDisabled || showFlowSubmitButton"
                :max="99999999"
                :min="0"
                v-model="model.mileage"
                placeholder="请输入里程数"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="!detailFlag">
            <a-form-model-item label="补贴单价(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subsidyUnitPrice">
              <j-dict-select-tag :disabled="formDisabled || showFlowSubmitButton" placeholder="请选择补贴单价" @input="subsidyUnitPriceInput" v-model="model.subsidyUnitPrice" dictCode="subsidy"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="!detailFlag">
            <a-form-model-item label="报销金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amount">
              <a-input-number
                :max="99999999"
                :min="0"
                v-model="model.amount"
                placeholder="请输入报销金额"
                style="width: 100%"
                disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="detailFlag">
            <a-form-model-item label="报销金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amount">
              <a-input-number
                :disabled="formDisabled"
                :max="99999999"
                :min="0"
                v-model="model.amount"
                @change="calculateAmount()"
                placeholder="请输入报销金额"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="!detailFlag">
            <a-form-model-item label="补助领款人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oilCard">
              <select-oil-card-persons-input :multi="false" :status="'1'" :disabled="formDisabled || showFlowSubmitButton" v-model="model.oilCard" @back="oilCardBack"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="detailFlag">
            <a-form-model-item label="税费金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxation">
              <a-input-number
                :disabled="formDisabled || isSpecialDisabled"
                :max="99999999"
                :min="0"
                v-model="model.taxation"
                @change="calculateAmount()"
                placeholder="请输入税费金额"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="detailFlag">
            <a-form-model-item label="未税金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="untaxedAmount">
              <a-input-number
                :disabled="datailDisabled"
                :max="99999999"
                :min="0"
                v-model="model.untaxedAmount"
                placeholder="请输入未税金额"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="detailFlag">
            <a-form-model-item label="税率(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxRate">
              <a-input-number :disabled="formDisabled || isTaxRateDisabled" :max="99999999" :min="0" :precision="0" v-model="model.taxRate" placeholder="请输入税率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.remark" rows="4" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import SelectProjectTaskInput from '@/views/scy/components/SelectProjectTaskInput'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import moment from 'moment'
import { mapGetters } from 'vuex';
import AddressChoice from '@/components/AddressChoice/AddressChoice';
import SelectOilCardPersonsInput from '@/views/scy/components/SelectOilCardPersonsInput'
import { Decimal } from 'decimal.js'

  export default {
    name: 'ErpFinanceTravelReimbursementDetailForm',
    components: {
      SelectProjectInput: () => import('@/views/scy/components/SelectProjectInput'),
      SelectProjectTaskInput,
      SelectTeamInput,
      SelectUserByDep,
      SelectOilCardPersonsInput,
      AddressChoice
    },
    props: {
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      showFlowSubmitButton: {
        type: Boolean,
        default: false,
        required: false
      },
      // 差旅明细(true:报销详情明细 false:自驾公里数补助明细)
      dateilType: {
        type: Boolean,
        required: false
      }
    },
    inject: ['layout'],
    data () {
      return {
        isSpecialDisabled: false,
        isTaxRateDisabled: false,
        flag: false,
        model: {
          detailType: 1,
          amount: null,
          taxation: null,
          setOutTime: null,
          backTime: null,
          startMileage: null,
          endMileage: null,
          oilCard: null,
          subsidyProposer: null
        },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 }
        },
        confirmLoading: false,
        validatorRules: {
          taxRate: [
              { required: true, message: '请输入正确的税率!'},
            ],
          departurePlace: [
              { required: true, message: '请选择出发地点!', trigger: 'change' }
          ],
          targetPlace: [
              { required: true, message: '请选择到达地点!', trigger: 'change' }
          ],
          startMileage: [
              { required: true, message: '请输入出发里程数!', trigger: 'blur' },
              { pattern: /^[0-9]*[1-9][0-9]*$/, message: '请输入正整数!' }
          ],
          endMileage: [
              { required: true, message: '请输入返程里程数!', trigger: 'blur' },
              { pattern: /^[0-9]*[1-9][0-9]*$/, message: '请输入正整数!' }
          ],
          isSpecial: [
              { required: true, message: '请选择发票类型!', trigger: 'blur' }
          ],
          amount: [
              { required: true, message: '请输入报销金额!', trigger: 'blur' },
              { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的报销金额!' }
          ],
          oilCard: [
            { required: true, message: '请选择补助领款人!', trigger: 'change' }
          ],
          setOutTime: [
              { required: true, message: '请选择出发时间!', trigger: 'change' }
          ],
          backTime: [
              { required: true, message: '请选择回程时间!', trigger: 'change' }
          ],
          feeType: [
              { required: true, message: '请选择报销内容!', trigger: 'blur' }
          ],
          selfDriving: [
              { required: true, message: '请选择报销内容!', trigger: 'blur' }
          ],
          taxation: []
        },
        detailFlag: false,
        datailDisabled: true,
        projectFlag: false,
        isRelProject: null
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      }
    },
    created () {
       // 备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      this.projectFlag = this.formDisabled
    },
    methods: {
      moment,
      ...mapGetters(['userInfo']),
      range (start, end) {
        const result = []
        for (let i = start; i < end; i++) {
          result.push(i)
        }
        return result
      },
      disabledDate(current) {
        return current < moment(moment(this.model.setOutTime).format('YYYY-MM-DD')).subtract('day')
      },
      disabledRangeTime() {
        const date = moment(this.model.setOutTime).format('yyyy-MM-DD HH')
        console.log(date)
        return {
          disabledHours: () => this.range(0, 24).splice(4, 20),
          disabledMinutes: () => this.range(30, 60),
          disabledSeconds: () => [55, 56]
        }
      },
      projectInput() {
        this.projectFlag = this.layout.projectFlag
        if (!this.projectFlag) {
          this.$set(this.validatorRules, 'projectId', [
              { required: true, message: '请选择关联项目!', trigger: 'change' }
          ]);
          this.$set(this.validatorRules, 'taskId', [
              { required: true, message: '请选择任务分类!', trigger: 'change' }
          ]);
        } else {
          this.$set(this.validatorRules, 'projectId', [
              { required: false, message: '请选择关联项目!', trigger: 'change' }
          ]);
          this.$set(this.validatorRules, 'taskId', [
              { required: false, message: '请选择任务分类!', trigger: 'change' }
          ]);
        }
      },

      //发票类型
      isSpecialInit(date){
        this.$refs.form.clearValidate('taxation');
        if (date == 0) { // 普票：税费和税率默认为0，发起人不可编辑和修改（流程中也不可修改）
          this.$delete(this.validatorRules, 'taxation');
          this.$delete(this.validatorRules, 'taxRate');
          this.$refs.form.clearValidate('taxation');
          this.$refs.form.clearValidate('taxRate');
          this.isSpecialDisabled=true;
          this.isTaxRateDisabled=true;
        } else if(date == 1) { // 专票：税费和税率为必填，发起人可编辑和修改 （税率计算公式：税费金额/未税金额取整，流程中都可修改）
          this.$refs.form.clearValidate('taxation');
          this.$set(this.validatorRules, 'taxRate', [{ required: true, message: '请输入正确的税率!'}]);
          this.$set(this.validatorRules, 'taxation', [
            { required: true, message: '请输入税费金额!', trigger: 'blur' },
            { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的税费金额!' }
          ]);
          this.isSpecialDisabled=false;
          this.isTaxRateDisabled=false;
        }else { // 其他或者不填：税费金额必填默认为0，发起人可修改，税率默认为0，发起人不可编辑和修改（流程中可以修改税费金额，不可修改税率）
          this.$delete(this.validatorRules, 'taxRate');
          this.$set(this.validatorRules, 'taxation', [
            { required: true, message: '请输入税费金额!', trigger: 'blur' },
            { pattern: /^(([0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的税费金额!' }
          ]);
          this.$refs.form.clearValidate('taxRate');
          this.isSpecialDisabled=false;
          this.isTaxRateDisabled=true;
        }
      },
      specialInput(date) {
        this.$refs.form.clearValidate('taxation');
        if (date == 0) { // 普票：税费和税率默认为0，发起人不可编辑和修改（流程中也不可修改）
          this.$set(this.model, 'taxation',0);
          this.$set(this.model, 'taxRate',0);
          this.$delete(this.validatorRules, 'taxation');
          this.$delete(this.validatorRules, 'taxRate');
          this.$refs.form.clearValidate('taxation');
          this.$refs.form.clearValidate('taxRate');
          this.isSpecialDisabled=true;
          this.isTaxRateDisabled=true;
          if (this.model.amount || this.model.amount == 0) {
            let money = new Decimal(this.model.amount).sub(new Decimal(this.model.taxation))
            this.model.untaxedAmount = money.toNumber().toFixed(2)
          }
        } else if(date == 1) { // 专票：税费和税率为必填，发起人可编辑和修改 （税率计算公式：税费金额/未税金额取整，流程中都可修改）
          this.$refs.form.clearValidate('taxation');
          this.$set(this.model, 'taxation',null);
          this.$set(this.model, 'taxRate',null);
          this.$set(this.validatorRules, 'taxRate', [{ required: true, message: '请输入正确的税率!'}]);
          this.$set(this.validatorRules, 'taxation', [
            { required: true, message: '请输入税费金额!', trigger: 'blur' },
            { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的税费金额!' }
          ]);
          this.isSpecialDisabled=false;
          this.isTaxRateDisabled=false;
          if (this.model.amount || this.model.amount == 0) {
            this.model.untaxedAmount = this.model.amount
          }
        }else { // 其他或者不填：税费金额必填默认为0，发起人可修改，税率默认为0，发起人不可编辑和修改（流程中可以修改税费金额，不可修改税率）
          this.$set(this.model, 'taxation',0);
          this.$set(this.model, 'taxRate',0);
          this.$delete(this.validatorRules, 'taxRate');
          this.$set(this.validatorRules, 'taxation', [
            { required: true, message: '请输入税费金额!', trigger: 'blur' },
            { pattern: /^(([0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的税费金额!' }
          ]);
          this.$refs.form.clearValidate('taxRate');
          this.isSpecialDisabled=false;
          this.isTaxRateDisabled=true;
          if (this.model.amount || this.model.amount == 0) {
            this.model.untaxedAmount = this.model.amount
          }
        }
      },
      subsidyUnitPriceInput(data) {
        let price = 0.5
        if (data == 1) {
          price = 1
        } else if (data == 2) {
          price = 1.5
        }
        if ((this.model.startMileage || this.model.startMileage == 0) && (this.model.endMileage || this.model.endMileage == 0)) {
          this.model.amount = price * this.model.mileage
        }
      },
      calculateMileage() {
        if ((this.model.startMileage || this.model.startMileage == 0) && (this.model.endMileage || this.model.endMileage == 0)) {
          this.model.mileage = this.model.endMileage - this.model.startMileage
          let mileage = new Decimal(this.model.endMileage).sub(new Decimal(this.model.startMileage))
          this.model.mileage = mileage.toNumber().toFixed(2)
        }
        if (this.model.subsidyUnitPrice) {
          this.subsidyUnitPriceInput(this.model.subsidyUnitPrice)
        }
      },
      calculateAmount() {
        if (this.model.amount || this.model.amount == 0) {
          let money = new Decimal(this.model.amount).sub(new Decimal(this.model.taxation || 0))
          this.model.untaxedAmount = money.toNumber().toFixed(2)
          // if(this.model.untaxedAmount>0){
          //   this.$set(this.model,'taxRate',(this.model.taxation/this.model.untaxedAmount*100).toFixed(0));
          // }else{
          //   this.$set(this.model,'taxRate',0);
          // }
          
        }
      },
      calculateDays() {
        if (!this.model.setOutTime) {
          this.model.backTime = null
          this.$message.warning('请先选择出发时间')
          return
        }
        if (!!this.model.setOutTime && !!this.model.backTime) {
          if (moment(this.model.backTime).diff(moment(this.model.setOutTime), 'hours') < 0) {
            this.model.backTime = this.model.setOutTime
            this.$message.warning('回程时间不得小于出发时间')
          }
          this.model.days = this.getDaysBetween(this.model.setOutTime, this.model.backTime)
        }
      },
      selectProject(data) {
        // this.model.teamId = data.choseObj[0].teamName
        if (data && data.choseObj && data.choseObj.length) {
          this.model.attributionYear = data.choseObj[0].year
          this.model.projectCode = data.choseObj[0].finalNo
        } else {
          this.model.attributionYear = null
          this.model.projectCode = null
        }
        this.$set(this.model, 'taskId', null)
        this.$set(this.model, 'taskDescription', null)
        // this.$set(this.model, 'teamYear', null)
      },
      taskBack(data) {
        this.model.taskDescription = data[0].taskDescription
      },
      add (val) {
        console.log(val);
        this.edit(this.modelDefault,val);
      },
      edit (record,isRelProject) {
        this.$refs['form'].clearValidate();
        this.model = Object.assign({}, record);
        this.isRelProject = isRelProject
        if (this.detailFlag) {
          this.model.detailType = 1
        } else {
          this.model.detailType = 2
        }
        this.isSpecialInit(this.model.isSpecial)
        // if (this.model.isSpecial == '0') {
        //   this.validatorRules.taxation = []
        // } else if (this.model.isSpecial == '1') {
        //   this.validatorRules.taxation = [
        //       { required: true, message: '请输入税费金额!', trigger: 'blur' },
        //       { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的税费金额!' }
        //   ]
        // }
        this.feeTypeInput(this.model.feeType)
        this.projectInput()
        this.visible = true;
      },
      feeTypeInput(item) {
        if (!!item && (item == 4 || item == 5)) {
          this.$set(this.validatorRules, 'isSpecial', [
              { required: false, message: '请选择发票类型!', trigger: 'blur' }
          ]);
        } else {
          this.$set(this.validatorRules, 'isSpecial', [
              { required: true, message: '请选择发票类型!', trigger: 'blur' }
          ]);
        }
      },
      oilCardBack(item) {
        if (item.length > 0) {
          this.$set(this.model, 'subsidyProposer', item[0].cardRecipient)
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            if (!!this.model.setOutTime) {
              this.model.setOutTime = moment(this.model.setOutTime).format('YYYY-MM-DD HH')+':00:00'
            }
            if (!!this.model.backTime) {
              this.model.backTime = moment(this.model.backTime).format('YYYY-MM-DD HH')+':00:00'
            }
            that.$emit('ok', this.model, this.flag);
          }
        })
      },
      getDaysBetween(date1, date2) {
        console.log(date1, date2);
        var startDate = Date.parse(date1);
        var endDate = Date.parse(date2);
        var date3 = endDate - startDate // 时间差的毫秒数
        // 计算出相差天数
        var days = Math.floor(date3 / (24 * 3600 * 1000))
        // 计算出小时数
        var leave1 = date3 % (24 * 3600 * 1000) // 计算天数后剩余的毫秒数
        var hours = Math.floor(leave1 / (3600 * 1000))

        const dayHours = days + '天' + hours + '小时'
        return dayHours;
      }
    }
  }
</script>
